package com.wude.http;

import android.util.Log;
import android.widget.TextView;

import com.mc.developmentkit.bean.LinkAgeInfo;
import com.mc.developmentkit.utils.ToastUtil;
import com.wude.bean.AboutUs;
import com.wude.bean.AddressBean;
import com.wude.bean.AppInfo;
import com.wude.bean.BangbiBean;
import com.wude.bean.ChoujiangBean;
import com.wude.bean.CommentariesBean;
import com.wude.bean.Generalize;
import com.wude.bean.GiftInfo;
import com.wude.bean.MyYaoqingBean;
import com.wude.bean.NoticeItemData;
import com.wude.bean.PinglunBean;
import com.wude.bean.ShareInfo;
import com.wude.bean.StartFuBean;
import com.wude.bean.TaskBean;
import com.wude.bean.TopTu;
import com.wude.bean.UserInfo;
import com.wude.tools.DbUtils;
import com.wude.tools.Utils;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.xutils.DbManager;

import java.util.ArrayList;
import java.util.List;

public class HttpUtils {

    /**
     * fragment 每日任务列表解析
     *
     * @param s
     */
    public static List<TaskBean> DNSTaskList(String s) {
        Log.e("每日任务列表解析json", s);
        List<TaskBean> taskBean = new ArrayList<>();
        try {
            JSONObject jsonObject1 = new JSONObject(s);
            int status = jsonObject1.getInt("status");
            if (status == 1) {
                JSONArray data = jsonObject1.getJSONArray("data");
                for (int i = 0; i < data.length(); i++) {
                    JSONObject jsonObject = data.getJSONObject(i);
                    TaskBean in = new TaskBean();
                    in.title = jsonObject.getString("title");
                    in.complete = jsonObject.getString("complete");
                    in.desc = jsonObject.getString("desc");
                    in.icon = jsonObject.getString("icon");
                    in.is_button = jsonObject.getInt("is_button");
                    in.numb = jsonObject.getString("numb");
                    in.points = jsonObject.getString("points");
                    taskBean.add(in);
                }
                return taskBean;
            } else {
                String return_code = jsonObject1.getString("return_code");
                Log.e("每日任务列表返回码", return_code);
                ToastUtil.showToast(return_code + "");
                return null;
            }
        } catch (JSONException e) {
            e.printStackTrace();
            Log.e("每日任务列表解析异常", e.toString());
            return null;
        }
    }

    /**
     * fragment Giftlist列表解析
     *
     * @param s
     */
    public static List<GiftInfo> DNSFragmentGiftList(String s) {
        Log.e("Fragment礼包列表json", s);
        List<GiftInfo> informationBeen = new ArrayList<>();
        try {
            JSONObject jsonObject1 = new JSONObject(s);
            int status = jsonObject1.getInt("status");
            if (status == 1) {
                JSONArray data = jsonObject1.getJSONArray("data");
                for (int i = 0; i < data.length(); i++) {
                    JSONObject jsonObject = data.getJSONObject(i);
                    GiftInfo in = new GiftInfo();
                    in.id = jsonObject.getInt("game_id");
                    in.giftbag_name = jsonObject.getString("giftbag_name");
                    in.icon = jsonObject.getString("icon");
                    in.num = jsonObject.getString("num");
                    in.jieshao = jsonObject.getString("giftbag_name");
                    in.desribe = jsonObject.getString("desribe");
                    in.introduction = jsonObject.getString("introduction");
                    in.game_name = jsonObject.getString("game_name");
                    in.receive = jsonObject.getString("receive");
                    in.gift_id = jsonObject.getInt("gift_id");
                    informationBeen.add(in);
                }
                return informationBeen;
            } else {
                String return_code = jsonObject1.getString("return_code");
                Log.e("礼包列表返回码", return_code);
                return null;
            }
        } catch (JSONException e) {
            e.printStackTrace();
            Log.e("解析Fragment礼包列表异常", e.toString());
            return null;
        }
    }

    /**
     * 验证身份证号真实姓名
     *
     * @param s
     * @return
     */
    public static boolean DNSYanZheng(String s) {
        Log.e("验证身份证号真实姓名json", s);
        try {
            JSONObject jsonObject = new JSONObject(s);
            int status = jsonObject.getInt("status");
            if (status == 1) {
                ToastUtil.showToast("提交成功");
                UserInfo loginUser = Utils.getLoginUser();
                loginUser.age_status = jsonObject.getInt("age_status");
                loginUser.real_name = jsonObject.getString("real_name");
                loginUser.idcard = jsonObject.getString("idcard");
                DbManager db = DbUtils.getDB();
                db.saveOrUpdate(loginUser);
                return true;
            } else {
                String data = jsonObject.getString("data");
                ToastUtil.showToast(data);
                return false;
            }
        } catch (Exception e) {
            Log.d("验证身份证号真实姓名失败", e.toString());
            return false;
        }

    }

    /**
     * 修改密码json
     *
     * @param s
     */
    public static boolean DNSChagePass(String s) {
        Log.e("修改密码json", s);
        try {
            JSONObject jsonObject = new JSONObject(s);
            int status = jsonObject.getInt("status");
            if (status == 1) {
                ToastUtil.showToast("修改成功");
                return true;
            } else {
                String return_code = jsonObject.getString("return_code");
                ToastUtil.showToast(return_code);
                return false;
            }
        } catch (JSONException e) {
            e.printStackTrace();
            return false;
        }
    }

    /**
     * 收货地址
     *
     * @param s
     */
    public static List<AddressBean> DNSAddress(String s) {
        Log.e("收货地址json", s);
        List<AddressBean> informationBeen = new ArrayList<>();
        try {
            JSONObject jsonObject1 = new JSONObject(s);
            int status = jsonObject1.getInt("status");
            if (status == 1) {
                JSONArray data = jsonObject1.getJSONArray("data");
                for (int i = 0; i < data.length(); i++) {
                    JSONObject jsonObject = data.getJSONObject(i);
                    AddressBean addressBean = new AddressBean();
                    addressBean.phone = jsonObject.getString("phone");
                    addressBean.address = jsonObject.getString("address");
                    addressBean.name = jsonObject.getString("name");
                    addressBean.shiqu = jsonObject.getString("city");
                    addressBean.id = jsonObject.getInt("id");
                    informationBeen.add(addressBean);
                }
                return informationBeen;
            } else {
                String return_code = jsonObject1.getString("return_code");
                Log.e("获取收货地址返回码", return_code);
                return null;
            }
        } catch (JSONException e) {
            e.printStackTrace();
            Log.e("解析收货地址异常", e.toString());
            return null;
        }
    }

    /**
     * 保存收货地址
     *
     * @param s
     * @return
     */
    public static boolean DNSSaveAddress(String s) {
        Log.e("保存收货地址json", s);
        try {
            JSONObject jsonObject = new JSONObject(s);
            int anInt = jsonObject.getInt("status");
            String string = jsonObject.getString("return_code");
            ToastUtil.showToast(string + "");
            if (anInt == 1) {
                return true;
            } else {
                Log.e("添加收货地址返回码", string);
                return false;
            }
        } catch (JSONException e) {
            e.printStackTrace();
            Log.e("解析收货地址失败", e.toString());
            return false;
        }
    }

    /**
     * 我的评论
     *
     * @param s
     */
    public static List<PinglunBean> DNSMyPinglun(String s, TextView v) {
        Log.e("我的评论json", s);
        List<PinglunBean> informationBeen = new ArrayList<>();
        try {
            JSONObject jsonObject1 = new JSONObject(s);
            int anInt = jsonObject1.getInt("status");
            if (anInt == 1) {
                JSONObject data1 = jsonObject1.getJSONObject("data");
                String count = data1.getString("count");
                v.setText("共" + count + "条评论");
                JSONArray data = data1.getJSONArray("data");
                for (int i = 0; i < data.length(); i++) {
                    JSONObject jsonObject = data.getJSONObject(i);
                    PinglunBean in = new PinglunBean();
                    in.name = jsonObject.getString("nickname");
                    in.time = jsonObject.getString("create_time");
                    in.icon = jsonObject.getString("head_img");
                    in.conte = jsonObject.getString("comment");
                    informationBeen.add(in);
                }
                return informationBeen;
            } else {
                String return_code = jsonObject1.getString("return_code");
                Log.e("我的评论返回码", return_code);
                return null;
            }
        } catch (JSONException e) {
            e.printStackTrace();
            Log.e("解析我的评论异常", e.toString());
            return null;
        }
    }

    /**
     * 解析我的收藏
     *
     * @param s
     */
    public static ArrayList<AppInfo> DNSSC(String s) {
        Log.e("我的收藏列表json", s);
        ArrayList<AppInfo> gameInfos = new ArrayList<>();
        try {
            JSONObject jsonObject1 = new JSONObject(s);
            int status = jsonObject1.getInt("status");
            if (status == 1) {
                JSONArray data = jsonObject1.getJSONArray("data");
                for (int i = 0; i < data.length(); i++) {
                    AppInfo gameInfo = new AppInfo();
                    JSONObject jsonObject = data.getJSONObject(i);
                    gameInfo.id = jsonObject.getInt("id");
                    gameInfo.name = jsonObject.getString("game_name");
                    gameInfo.rating = (float) jsonObject.getInt("ratio");
                    gameInfo.size = jsonObject.getString("game_size");
                    gameInfo.iconurl = jsonObject.getString("icon");
                    gameInfo.features = jsonObject.getString("features");
                    gameInfo.DownNum = jsonObject.getInt("dow_num");
                    gameInfos.add(gameInfo);
                }
                return gameInfos;
            } else {
                String return_code = jsonObject1.getString("return_code");
                Log.e("我的收藏返回码", return_code);
                return null;
            }
        } catch (Exception e) {
            e.printStackTrace();
            Log.e("解析游戏列表出错", e.toString());
            return null;
        }
    }

    /**
     * 领取礼包记录
     *
     * @param
     */
    public static List<GiftInfo> DNSGiftJL(String s) {
        Log.e("礼包记录json", s);
        List<GiftInfo> informationBeen = new ArrayList<>();
        try {
            JSONObject jsonObject1 = new JSONObject(s);
            int status = jsonObject1.getInt("status");
            int return_code = jsonObject1.getInt("return_code");
            if (status == 1) {
                JSONArray data = jsonObject1.getJSONArray("data");
                for (int i = 0; i < data.length(); i++) {
                    JSONObject jsonObject = data.getJSONObject(i);
                    GiftInfo in = new GiftInfo();
                    in.giftbag_name = jsonObject.getString("gift_name");
                    in.game_name = jsonObject.getString("game_name");
                    in.icon = jsonObject.getString("icon");
                    in.start_time = jsonObject.getString("start_time");
                    in.end_time = jsonObject.getString("end_time");
                    in.jihuoma = jsonObject.getString("novice");
                    in.gift_id = jsonObject.getInt("gift_id");
                    informationBeen.add(in);
                }
                return informationBeen;
            } else {
                Log.e("礼包记录状态值", "" + return_code);
                return null;
            }
        } catch (JSONException e) {
            e.printStackTrace();
            Log.e("解析礼包记录异常", e.toString());
            return null;
        }
    }

    /**
     * 获取可代充游戏列表
     *
     * @param s
     */
    public static List<LinkAgeInfo> DNSGameCanPay(String s) {
        Log.e("获取可代充游戏列表json", s);
        List<LinkAgeInfo> carouselFigures = new ArrayList<>();
        try {
            JSONObject jsonObject = new JSONObject(s);
            int status = jsonObject.getInt("status");
            String msg = jsonObject.getString("return_code");
            if (status == 1) {
                JSONArray jsonArray = jsonObject.getJSONArray("data");
                for (int i = 0; i < jsonArray.length(); i++) {
                    JSONObject jsonObject1 = jsonArray.getJSONObject(i);
                    LinkAgeInfo linkAgeInfo = new LinkAgeInfo();
                    linkAgeInfo.id = jsonObject1.getInt("game_id");
                    String game_name = jsonObject1.getString("game_name");
                    linkAgeInfo.name = Utils.getJieQu(game_name);
                    carouselFigures.add(linkAgeInfo);
                }
                return carouselFigures;
            } else {
                Log.e("获取代充游戏返回码", msg);
                return null;
            }
        } catch (JSONException e) {
            e.printStackTrace();
            Log.e("获取可代充游戏列表json出错", e.toString());
            return null;
        }
    }

    /**
     * 获取折扣
     *
     * @param s
     */
    public static Double DNSDiscount(String s) {
        Log.e("获取折扣json", s);
        try {
            JSONObject jsonObject = new JSONObject(s);
            int status = jsonObject.getInt("status");
            if (status == 1) {
                Double discount = jsonObject.getDouble("data");
                return discount;
            } else {
                String msg = jsonObject.getString("msg");
                ToastUtil.showToast(msg);
                return 10.0;
            }
        } catch (JSONException e) {
            e.printStackTrace();
            Log.e("获取折扣错误", e.toString());
            return 10.0;
        }
    }

    /**
     * 绑币记录
     *
     * @param s
     */
    public static List<BangbiBean> DNSBBJL(String s) {
        Log.e("绑定平台币记录json", s);
        List<BangbiBean> informationBeen = new ArrayList<>();
        try {
            JSONObject jsonObject1 = new JSONObject(s);
            int status = jsonObject1.getInt("status");
            if (status == 1) {
                JSONArray data = jsonObject1.getJSONArray("data");
                for (int i = 0; i < data.length(); i++) {
                    JSONObject jsonObject = data.getJSONObject(i);
                    BangbiBean in = new BangbiBean();
                    in.name = jsonObject.getString("game_name");
                    in.yue = jsonObject.getString("bind_balance");
                    informationBeen.add(in);
                }
                return informationBeen;
            } else {
                String return_code = jsonObject1.getString("return_code");
                ToastUtil.showToast(return_code);
                return null;
            }
        } catch (JSONException e) {
            e.printStackTrace();
            Log.e("解析绑定记录异常", e.toString());
            return null;
        }
    }

    /**
     * 解析用户信息
     *
     * @param json
     * @return
     */
    public static UserInfo DNSUser(String json) {
        Log.e("用户信息json", json);
        try {
            JSONObject jsonObject = new JSONObject(json);
            int int1 = jsonObject.getInt("status");
            if (int1 == 1) {
                UserInfo loginUser = Utils.getLoginUser();
                JSONObject jsonObject2 = jsonObject.getJSONObject("data");
                loginUser.balance = jsonObject2.getString("balance");
                loginUser.phone = jsonObject2.getString("phone");
                loginUser.tou = jsonObject2.getString("head_img");
                loginUser.sex = jsonObject2.getInt("sex");
                loginUser.account = jsonObject2.getString("account");
                if (jsonObject2.getString("point") == null || jsonObject2.getString("point").equals("null")) {
                    loginUser.jifen = "0";
                } else {
                    loginUser.jifen = jsonObject2.getString("point");
                }
                loginUser.nickname = jsonObject2.getString("nickname");
                loginUser.idcard = jsonObject2.getString("idcard");
                loginUser.age_status = jsonObject2.getInt("age_status");
                loginUser.real_name = jsonObject2.getString("real_name");
                loginUser.all_flow = jsonObject2.getString("all_flow");
                loginUser.point = jsonObject2.getString("point");

                DbManager db = DbUtils.getDB();
                db.saveOrUpdate(loginUser);
                return loginUser;
            } else {
                int return_code = jsonObject.getInt("return_code");
                Log.e("获取用户信息返回码", "" + return_code);
                return null;
            }
        } catch (Exception e) {
            Log.e("用户信息报错", e.toString());
            return null;
        }

    }

    /**
     * 我的邀请
     *
     * @param s
     */
    public static List<MyYaoqingBean> DNSMyYaoqing(String s) {
        Log.e("我的邀请json", s);
        List<MyYaoqingBean> informationBeen = new ArrayList<>();
        try {
            JSONObject jsonObject1 = new JSONObject(s);
            int status = jsonObject1.getInt("status");
            if (status == 1) {
                JSONArray data = jsonObject1.getJSONArray("data");
                for (int i = 0; i < data.length(); i++) {
                    JSONObject jsonObject = data.getJSONObject(i);
                    MyYaoqingBean in = new MyYaoqingBean();
                    in.account = jsonObject.getString("user_account");
                    in.time = jsonObject.getString("create_time");
                    in.qian = jsonObject.getString("award_coin");
                    informationBeen.add(in);
                }
                return informationBeen;
            } else {
                String string = jsonObject1.getString("");
                ToastUtil.showToast(string);
                return null;
            }
        } catch (JSONException e) {
            e.printStackTrace();
            Log.e("解析我的邀请异常", e.toString());
            return null;
        }
    }

    /**
     * 游戏评论
     *
     * @param s
     */
    public static ArrayList<Generalize> DNSGeneralize(String s) {
        Log.e("推广游戏列表json", s);
        ArrayList<Generalize> gameInfos = new ArrayList<>();
        try {
            JSONObject jsonObject1 = new JSONObject(s);
            int status = jsonObject1.getInt("status");
            String return_code = jsonObject1.getString("return_code");
            if (status == 1) {
//                JSONObject data1 = jsonObject1.getJSONObject("data");
                JSONArray data = jsonObject1.getJSONArray("data");
                for (int i = 0; i < data.length(); i++) {
                    Generalize gameInfo = new Generalize();
                    JSONObject jsonObject = data.getJSONObject(i);
                    gameInfo.game_id = jsonObject.getString("id");
                    gameInfo.game_name = jsonObject.getString("game_name");
                    gameInfo.dow_status = jsonObject.getString("dow_status");
//                    gameInfo.pack_url = jsonObject.getString("pack_url");
                    gameInfo.dow_url = jsonObject.getString("dow_url");
                    gameInfo.icon = jsonObject.getString("icon");
                    gameInfo.game_type_name = jsonObject.getString("game_type_name");
                    gameInfo.game_size = jsonObject.getString("game_size");
                    gameInfo.features = jsonObject.getString("features");
//                    gameInfo.status = jsonObject.getString("status");
//                    gameInfo.apk_pck_name = jsonObject.getString("apk_pck_name");
                    gameInfos.add(gameInfo);
                }
                return gameInfos;
            } else {
                Log.e("解析推广游戏列表出错", return_code);
                return null;
            }
        } catch (Exception e) {
            e.printStackTrace();
            Log.e("解析推广游戏列表出错", e.toString());
            return null;
        }
    }

    /**
     * 动态列表
     *
     * @param s
     */
    public static ArrayList<CommentariesBean> DNSCommentaries(String s) {
        Log.e("动态列表json", s);
        ArrayList<CommentariesBean> gameInfos = new ArrayList<>();
        try {
            JSONObject jsonObject1 = new JSONObject(s);
            int status = jsonObject1.getInt("status");
            String return_code = jsonObject1.getString("return_code");
            if (status == 1) {
                JSONObject data1 = jsonObject1.getJSONObject("data");
                JSONArray data = data1.getJSONArray("data");
                for (int i = 0; i < data.length(); i++) {
                    CommentariesBean gameInfo = new CommentariesBean();
                    JSONObject jsonObject = data.getJSONObject(i);
                    gameInfo.account = jsonObject.getString("account");
                    gameInfo.create_time = jsonObject.getString("create_time");
                    gameInfo.comment = jsonObject.getString("comment");
                    gameInfo.game_id = jsonObject.getString("game_id");
                    gameInfo.nickname = jsonObject.getString("nickname");
                    gameInfo.head_img = jsonObject.getString("head_img");
                    gameInfo.game_name = jsonObject.getString("game_name");
                    gameInfo.game_icon = jsonObject.getString("game_icon");
                    gameInfos.add(gameInfo);
                }
                return gameInfos;
            } else {
                Log.e("解析动态列表出错", return_code);
                return null;
            }
        } catch (Exception e) {
            e.printStackTrace();
            Log.e("解析动态列表出错", e.toString());
            return null;
        }
    }

    /**
     * 游戏详情内的区服信息
     *
     * @param s
     */
    public static ArrayList<StartFuBean> DNSQUfu(String s) {
        Log.e("解析区服信息列表", s);
        ArrayList<StartFuBean> gameInfos = new ArrayList<>();
        try {
            JSONObject jsonObject1 = new JSONObject(s);
            int status = jsonObject1.getInt("status");
            String return_code = jsonObject1.getString("return_code");
            if (status == 1) {
                JSONArray data = jsonObject1.getJSONArray("data");
                for (int i = 0; i < data.length(); i++) {
                    StartFuBean gameInfo = new StartFuBean();
                    JSONObject jsonObject = data.getJSONObject(i);
                    gameInfo.time = jsonObject.getString("start_time");
                    gameInfo.qu = jsonObject.getString("server_name");
                    gameInfos.add(gameInfo);
                }
                return gameInfos;
            } else {
                Log.e("游戏详情内区服状态值", return_code);
                return null;
            }
        } catch (Exception e) {
            e.printStackTrace();
            Log.e("解析区服信息出错", e.toString());
            return null;
        }
    }

    /**
     * 获取单个礼包列表
     *
     * @param s
     */
    public static List<GiftInfo> DNSGiftList(String s) {
        Log.e("单个礼包列表json", s);
        List<GiftInfo> informationBeen = new ArrayList<>();
        try {
            JSONObject jsonObject1 = new JSONObject(s);
            int status = jsonObject1.getInt("status");
            int return_code = jsonObject1.getInt("return_code");
            if (status == 1) {
                JSONArray data = jsonObject1.getJSONArray("data");
                for (int i = 0; i < data.length(); i++) {
                    JSONObject jsonObject = data.getJSONObject(i);
                    GiftInfo in = new GiftInfo();
                    in.gift_id = jsonObject.getInt("id");
                    in.giftbag_name = jsonObject.getString("giftbag_name");
                    in.icon = jsonObject.getString("icon");
                    in.jieshao = jsonObject.getString("desribe");
                    in.num = jsonObject.getString("novice_num");
                    informationBeen.add(in);
                }
                return informationBeen;
            } else {
                Log.e("礼包返回状态值", "" + return_code);
                return null;
            }
        } catch (JSONException e) {
            e.printStackTrace();
            Log.e("解析单个礼包列表异常", e.toString());
            return null;
        }
    }

    /**
     * 领取激活码
     *
     * @param s
     * @return
     */
    public static String DNSLingQu(String s) {
        Log.e("领取激活码json", s);
        try {
            JSONObject jsonObject = new JSONObject(s);
            int status = jsonObject.getInt("status");
            if (status == 1) {
                String data = jsonObject.getString("data");
                return data;
            } else {
                String return_code = jsonObject.getString("return_code");
                ToastUtil.showToast(return_code);
                return null;
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
        return null;
    }

    /**
     * 是否收藏
     *
     * @param s
     * @return
     */
    public static boolean DNSShou(String s) {
        Log.e("是否收藏json", s);
        try {
            JSONObject jsonObject = new JSONObject(s);
            int status = jsonObject.getInt("status");
            if (status == 1) {
                return true;
            } else {
                String string = jsonObject.getString("return_code");
                ToastUtil.showToast(string);
                return false;
            }
        } catch (JSONException e) {
            e.printStackTrace();
            Log.e("是否收藏出错", e.toString());
            return false;
        }
    }

    /**
     * 解析分享
     *
     * @param s
     * @return
     */
    public static ShareInfo DNSShare(String s) {
        Log.e("获取分享json", s);
        try {
            JSONObject jsonObject = new JSONObject(s);
            int anInt = jsonObject.getInt("status");
            if (anInt == 1) {
                JSONObject data = jsonObject.getJSONObject("data");
                ShareInfo shareInfo = new ShareInfo();
                shareInfo.title = data.getString("title");
                shareInfo.logoUrl = data.getString("icon");
                shareInfo.text = data.getString("content");
                shareInfo.shareUrl = data.getString("url");
                return shareInfo;
            } else {
                String return_code = jsonObject.getString("return_code");
                Log.e("获取分享信息返回码", return_code);
                return null;
            }
        } catch (JSONException e) {
            e.printStackTrace();
            return null;
        }
    }

    /**
     * 发表游戏评论
     *
     * @param s
     * @return
     */
    public static boolean DNSPiNGLUN(String s) {
        Log.e("发表游戏评论json", s);
        try {
            JSONObject jsonObject = new JSONObject(s);
            int anInt = jsonObject.getInt("status");
            String string = jsonObject.getString("return_code");
            if (anInt == 1) {
                ToastUtil.showToast("提交成功等待审核");
                return true;
            } else {
                ToastUtil.showToast(string);
                return false;
            }
        } catch (JSONException e) {
            e.printStackTrace();
            Log.e("解析游戏评论失败", e.toString());
            return false;
        }
    }

    /**
     * 游戏评论
     *
     * @param s
     */
    public static ArrayList<PinglunBean> DNSPinglun(String s) {
        Log.e("游戏评论json", s);
        ArrayList<PinglunBean> gameInfos = new ArrayList<>();
        try {
            JSONObject jsonObject1 = new JSONObject(s);
            int status = jsonObject1.getInt("status");
            String return_code = jsonObject1.getString("return_code");
            if (status == 1) {
                JSONObject data1 = jsonObject1.getJSONObject("data");
                JSONArray data = data1.getJSONArray("data");
                for (int i = 0; i < data.length(); i++) {
                    PinglunBean gameInfo = new PinglunBean();
                    JSONObject jsonObject = data.getJSONObject(i);
                    gameInfo.icon = jsonObject.getString("head_img");
                    gameInfo.name = jsonObject.getString("nickname");
                    gameInfo.conte = jsonObject.getString("comment");
                    gameInfo.time = jsonObject.getString("create_time");
                    JSONArray imgurl = jsonObject.getJSONArray("imgurl");
                    for (int j = 0; j < imgurl.length(); j++) {
                        if (gameInfo.imgurl == null)
                            gameInfo.imgurl = new ArrayList<>();
                        gameInfo.imgurl.add(imgurl.get(j).toString());
                    }
                    gameInfos.add(gameInfo);
                }
                return gameInfos;
            } else {
                Log.e("游戏评论状态值", return_code);
                return null;
            }
        } catch (Exception e) {
            e.printStackTrace();
            Log.e("解析游戏评论出错", e.toString());
            return null;
        }
    }

    /**
     * 解析游戏排行榜列表
     *
     * @param s
     * @return
     */
    public static ArrayList<AppInfo> DNSGameList(String s) {
        Log.e("解析游戏排行列表", s);
        ArrayList<AppInfo> gameInfos = new ArrayList<>();
        try {
            JSONObject jsonObject1 = new JSONObject(s);
            int status = jsonObject1.getInt("status");
            if (status == 1) {
                JSONArray data = jsonObject1.getJSONArray("data");
                for (int i = 0; i < data.length(); i++) {
                    AppInfo gameInfo = new AppInfo();
                    JSONObject jsonObject = data.getJSONObject(i);
                    gameInfo.id = jsonObject.getInt("id");
                    gameInfo.name = jsonObject.getString("game_name");
                    gameInfo.rating = (float) jsonObject.getInt("game_score");
                    gameInfo.size = jsonObject.getString("game_size");
//                    gameInfo.name = jsonObject.getString("game_name");
                    gameInfo.DownNum = jsonObject.getInt("dow_num");
                    gameInfo.packname = jsonObject.getString("pack_name");
                    gameInfo.iconurl = jsonObject.getString("icon");
                    gameInfo.fanli = jsonObject.getString("ratio");
                    gameInfo.features = jsonObject.getString("features");
                    gameInfo.cover_banner = jsonObject.getString("cover_banner");
                    gameInfos.add(gameInfo);
                }
                return gameInfos;
            } else {
                Log.e("后台返回状态", status + "");
                return null;
            }
        } catch (Exception e) {
            e.printStackTrace();
            Log.e("解析游戏列表出错", e.toString());
            return null;
        }
    }

    /**
     * 游戏详情
     *
     * @param s
     */
    public static AppInfo DNSGameDel(String s) {
        Log.e("游戏详情页面json", s);
        try {
            JSONObject jsonObject = new JSONObject(s);
            int status = jsonObject.getInt("status");
            if (status == 1) {
                JSONObject data = jsonObject.getJSONObject("data");
                AppInfo appInfo = new AppInfo();
                appInfo.name = data.getString("game_name");
                appInfo.iconurl = data.getString("icon");
                appInfo.DownNum = data.getInt("dow_num");
                appInfo.id = data.getInt("id");
                appInfo.Collection = data.getInt("is_collect");
                appInfo.size = data.getString("game_size");
                appInfo.introduce = data.getString("introduction");
                appInfo.features = data.getString("features");
                appInfo.fanli = data.getString("ratio");
                appInfo.discount = data.getString("discount");
                appInfo.rating = (float) data.getInt("game_score");
                JSONArray screenshot = data.getJSONArray("screenshot");
                for (int i = 0; i < screenshot.length(); i++) {
                    String string = screenshot.getString(i);
                    appInfo.jietu.add(string);
                }
                return appInfo;
            } else {
                ToastUtil.showToast("后台返回状态值" + status);
                return null;
            }
        } catch (JSONException e) {
            e.printStackTrace();
            Log.e("解析游戏详情页面异常", e.toString());
            return null;
        }
    }

    /**
     * 返回下载链接
     *
     * @param string
     * @return
     */
    public static String DNSdownUrl(String string) {
        Log.e("获取下载链接JSON", string);
        try {
            JSONObject jsonObject = new JSONObject(string);
            int int1 = jsonObject.getInt("status");
            if (int1 == 1) {
                String string2 = jsonObject.getString("data");
                return string2;
            } else {
                String string2 = jsonObject.getString("return_code");
                Utils.TS(string2);
                return null;
            }
        } catch (JSONException e) {
            e.printStackTrace();
            Log.e("解析获取下载错误", e.toString());
            return null;
        }
    }

    public static ArrayList<NoticeItemData> DNSHomeMessge(String s) {
        Log.e("首页消息通知json", s);
        ArrayList<NoticeItemData> beans = new ArrayList<>();
        try {
            JSONObject jsonObject1 = new JSONObject(s);
            int status = jsonObject1.getInt("status");
            String return_code = jsonObject1.getString("return_code");
            if (status == 1) {
                JSONArray data = jsonObject1.getJSONArray("data");
                for (int i = 0; i < data.length(); i++) {
                    NoticeItemData itemData = new NoticeItemData();
                    JSONObject jsonObject = data.getJSONObject(i);
                    itemData.lottery_name = jsonObject.getString("lottery_name");
                    beans.add(itemData);
                }
                return beans;
            } else {
                Log.e("解析首页消息通知", return_code);
                return null;
            }
        } catch (Exception e) {
            e.printStackTrace();
            Log.e("解析首页消息通知出错", e.toString());
            return null;
        }
    }

    /**
     * Top自动轮播图 广告条
     *
     * @param json
     * @return
     */
    public static ArrayList<TopTu> DNSTopTu(String json) {
        ArrayList<TopTu> Toplist = new ArrayList<TopTu>();
        Log.e("轮播图json", json);
        try {
            JSONObject jsonObject = new JSONObject(json);
            JSONArray jsonArray = jsonObject.getJSONArray("data");
            for (int i = 0; i < jsonArray.length(); i++) {
                JSONObject jsonObject2 = jsonArray.getJSONObject(i);
                TopTu searchPager = new TopTu();
                searchPager.guan = jsonObject2.getString("url");
                searchPager.url = jsonObject2.getString("data");
                searchPager.title = jsonObject2.getString("title");
                Toplist.add(searchPager);
            }
            return Toplist;
        } catch (JSONException e) {
            e.printStackTrace();
            Log.e("解析轮播图出错", e.toString());
            return null;
        }
    }

    public static ArrayList<String> DNSNoticeItem(String s) {
        Log.e("中奖名单json", s);
        ArrayList<String> beans = new ArrayList<>();
        try {
            JSONObject jsonObject1 = new JSONObject(s);
            int status = jsonObject1.getInt("status");
            String return_code = jsonObject1.getString("return_code");
            if (status == 1) {
                JSONObject object = new JSONObject(s);
                JSONObject object1 = object.getJSONObject("data");
                JSONArray data = object1.getJSONArray("lottery_name");
                for (int i = 0; i < data.length(); i++) {
                    beans.add(data.getString(i));
                }
                return beans;
            } else {
                Log.e("解析抽奖出错", return_code);
                return null;
            }
        } catch (Exception e) {
            e.printStackTrace();
            Log.e("解析抽奖出错", e.toString());
            return null;
        }
    }

    /**
     * 抽奖
     *
     * @param s
     */
    public static ArrayList<ChoujiangBean> DNSChoujiang(String s) {
        Log.e("抽奖json", s);
        ArrayList<ChoujiangBean> beans = new ArrayList<>();
        try {
            JSONObject jsonObject1 = new JSONObject(s);
            int status = jsonObject1.getInt("status");
            String return_code = jsonObject1.getString("return_code");
            if (status == 1) {
                JSONObject data1 = jsonObject1.getJSONObject("data");
                JSONArray data = data1.getJSONArray("data");
                for (int i = 0; i < data.length(); i++) {
                    ChoujiangBean gameInfo = new ChoujiangBean();
                    JSONObject jsonObject = data.getJSONObject(i);
                    gameInfo.id = jsonObject.getString("id");
                    gameInfo.name = jsonObject.getString("name");
                    gameInfo.icon = jsonObject.getString("icon");
                    gameInfo.cate = jsonObject.getString("cate");
                    gameInfo.number = jsonObject.getString("number");
                    gameInfo.status = jsonObject.getString("status");
                    beans.add(gameInfo);
                }
                return beans;
            } else {
                Log.e("解析抽奖出错", return_code);
                return null;
            }
        } catch (Exception e) {
            e.printStackTrace();
            Log.e("解析抽奖出错", e.toString());
            return null;
        }
    }

    /**
     * 更新用户信息
     *
     * @param s
     * @return
     */
    public static boolean DNSGengxin(String s) {
        Log.e("更新用户信息json", s);
        try {
            JSONObject jsonObject = new JSONObject(s);
            int status = jsonObject.getInt("status");
            String anInt1 = jsonObject.getString("return_code");
            ToastUtil.showToast(anInt1);
            if (status == 1) {
                UserInfo loginUser = Utils.getLoginUser();
                JSONObject data = jsonObject.getJSONObject("data");
                loginUser.account = data.getString("account");
                loginUser.nickname = data.getString("nickname");
                loginUser.tou = data.getString("head_img");
                loginUser.balance = data.getString("balance");
                loginUser.phone = data.getString("phone");
                loginUser.token = data.getString("token");
                loginUser.sex = data.getInt("sex");
                loginUser.all_flow = data.getString("all_flow");
                loginUser.id = 1;
                String point = data.getString("point");
                loginUser.jifen = point == null || point.equals("null") ? "0" : point;
                DbManager db = DbUtils.getDB();
                db.delete(UserInfo.class);
                db.saveOrUpdate(loginUser);
                return true;
            } else {
                return false;
            }
        } catch (Exception e) {
            e.printStackTrace();
            Log.e("更新用户信息json", s);
            return false;
        }
    }

    /**
     * 解析忘记密码
     *
     * @param s
     * @return
     */
    public static boolean DNSForget(String s) {
        Log.e("忘记密码json", s);
        try {
            JSONObject jsonObject = new JSONObject(s);
            int status = jsonObject.getInt("status");
            String anInt1 = jsonObject.getString("return_code");
            ToastUtil.showToast(anInt1);
            if (status == 1) {
                return true;
            } else {
                return false;
            }
        } catch (JSONException e) {
            e.printStackTrace();
            Log.e("忘记密码json", s);
            return false;
        }
    }

    /**
     * 用户注册
     *
     * @param s
     */
    public static int DNSRegister(String s) {
        Log.e("注册返回json", s);
        try {
            JSONObject jsonObject = new JSONObject(s);
            int anInt = jsonObject.getInt("status");
            int string = jsonObject.getInt("return_code");
            if (anInt == 1) {
                JSONObject data = jsonObject.getJSONObject("data");
                UserInfo userInfo = new UserInfo();
                userInfo.account = data.getString("account");
                userInfo.nickname = data.getString("nickname");
                userInfo.token = data.getString("token");
                userInfo.id = 1;
                userInfo.jifen = "0";
                DbManager db = DbUtils.getDB();
                db.delete(UserInfo.class);
                db.saveOrUpdate(userInfo);
                return string;
            } else {
                return string;
            }
        } catch (Exception e) {
            e.printStackTrace();
            Log.e("解析注册返回出错", e.toString());
            return 0;
        }
    }

    /**
     * 关于我们
     *
     * @param s
     * @return
     */
    public static AboutUs DNSAboutUs(String s) {
        Log.e("关于我们json", s);
        try {
            JSONObject jsonObject = new JSONObject(s);
            int status = jsonObject.getInt("status");
            if (status == 1) {
                JSONObject jsonObject2 = jsonObject.getJSONObject("data");
                AboutUs shopDetBean = new AboutUs();
                shopDetBean.iconUrl = jsonObject2.getString("about_ico");
                shopDetBean.appname = jsonObject2.getString("app_name");
                shopDetBean.gongzhonghao = jsonObject2.getString("weixin");
                shopDetBean.guanwang = jsonObject2.getString("network");
                shopDetBean.kefuQQ = jsonObject2.getString("qq");
                shopDetBean.wanjiaqun = jsonObject2.getString("qq_group");
                shopDetBean.wanjiaqunkey = jsonObject2.getString("qq_group_key");
                shopDetBean.version_name = jsonObject2.getString("version_name");
                shopDetBean.version_hao = jsonObject2.getString("version");
                shopDetBean.versionUrl = jsonObject2.getString("app_download");
                shopDetBean.version_log = jsonObject2.getString("version_log");
                return shopDetBean;
            } else {
                String msg = jsonObject.getString("msg");
                Utils.TS(msg);
                return null;
            }
        } catch (JSONException e) {
            e.printStackTrace();
            Log.e("解析关于我们出错", e.toString());
            return null;
        }
    }

    /**
     * 解析用户登录
     *
     * @param s
     */
    public static int DNSLogin(String s) {
        Log.e("用户登录json", s);
        try {
            JSONObject jsonObject = new JSONObject(s);
            int anInt = jsonObject.getInt("status");
            int anInt1 = jsonObject.getInt("return_code");
            if (anInt == 1) {
                UserInfo userInfo = new UserInfo();
                JSONObject data = jsonObject.getJSONObject("data");
                userInfo.account = data.getString("account");
                userInfo.nickname = data.getString("nickname");
                userInfo.tou = data.getString("head_img");
                userInfo.balance = data.getString("balance");
                userInfo.token = data.getString("token");
                userInfo.all_flow = data.getString("all_flow");
                userInfo.id = 1;
                String point = data.getString("point");
                userInfo.jifen = point == null || point.equals("null") ? "0" : point;
                userInfo.bindphone = data.getString("bindphone");
                DbManager db = DbUtils.getDB();
                db.delete(UserInfo.class);
                db.saveOrUpdate(userInfo);
                return anInt1;
            } else {
                return anInt1;
            }
        } catch (Exception e) {
            e.printStackTrace();
            Log.e("解析用户登录失败", e.toString());
            return 0;
        }
    }

}
